package com.wanxi.servlet;

import com.wanxi.model.UserModel;
import com.wanxi.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/d")
public class DataServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.设置乱码
        req.setCharacterEncoding("UTF-8");
//        2.得到前端的值
        String username = req.getParameter("username");
        String pass = req.getParameter("username");
        String sex = req.getParameter("username");
        String phone = req.getParameter("username");
        String email = req.getParameter("username");
        String address = req.getParameter("username");
        String birthday = req.getParameter("username");
//        编写复杂的逻辑关系，和当前方法的代码功能不同
        UserModel user=new UserModel();
//        user.setAddress(address);
//        user.setAddress(address);
//        user.setAddress(address);
//        user.setAddress(address);
//        user.setAddress(address);
        UserService user1=new UserService();
        user1.aa(user);
//        如果遇到参数都差不多，或者理解为可以封装为一个对象的时候，则不要用参数
//        以后，参数不同的功能最好不操作两个
//        3.将值存入到req

        req.setAttribute("aa", username);
        System.out.println(req.getAttribute("aa"));
//        req.getSession().setAttribute("aa", username);
//        req.getServletContext().setAttribute("aa", username);
//        4.将数据转发到页面
        req.getRequestDispatcher("/index.jsp").forward(req, resp);
    }


}
